System Container Margins
The contentMargins modifier configures custom margins around a view’s content. This allows precise control over layout spacing, particularly in scrollable containers such as ScrollView, List, or Form. You can apply margins uniformly or selectively to certain edges and placement contexts.
Type
Parameters
insets (required)
Defines the margin values to apply. You can provide:
- A single number (applied to all specified edges)
- An
EdgeInsetsobject for per-edge customization
Example – uniform insets:
Example – edge-specific insets:
edges (optional)
Defines which edges the insets should apply to. If omitted, all edges are used.
Type
Example – apply to top and bottom only:
placement (optional)
Specifies where in the layout the margins should be applied. This is especially relevant in scrollable views that have both scrollable content and indicators.
Type
Options
Example – margin applied only to scrollable content:
Full Configuration Example
Summary
System container margin guide (iOS 27.1+)
contentMargins also accepts { guide: "container", edges?: EdgeSet, alignment?: Alignment }. It uses the system container margin guide rather than a numeric inset. Edges default to all, and omitted alignment uses native automatic alignment. Earlier systems ignore this form; existing number/insets/placement forms retain their behavior. Direct and fluent modifiers support it.
